﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class RoomInfoPage : EventManager
{
    public override void InformationSetting()
    {
        Init();
    }

    public Text roomName;
    public Text createRoomTime;
    public Text roomHost;
    public Text roomId;
    public Text botScore;
    public Text empowerTakeIn;
    public Text zhuang;
    public Text sameNiu;
    public Text oneTimesBet;
    public Text autoNiu;
    public Button shareBtn;
    public Button roomSet;
    public Button disSolveRoomBtn;
    public Button closeBtn;

    private void Init()
    {
        AddListenerToButton(roomSet, RoomSetBtnClick);
        AddListenerToButton(disSolveRoomBtn, DisSolveRoomBtnClick);
        AddListenerToButton(shareBtn, ShareBtnClick);
        AddListenerToButton(closeBtn, CloseBtnClick);
        SetText(roomName, GameRoomModel.GetInstance().RoomName);
        SetText(createRoomTime, GameRoomModel.GetInstance().CreateRoomTime);
        SetText(roomHost, GameRoomModel.GetInstance().CreateRoomUserName);
        SetText(roomId, GameRoomModel.GetInstance().RoomID);
        SetText(botScore, GameRoomModel.GetInstance().BotScore.ToString());
        if (GameData.GetInstance().userID == GameData.GetInstance().roomHostUserID)
        {
            roomSet.GetComponent<Button>().interactable = true;
            disSolveRoomBtn.GetComponent<Button>().interactable = true;
        }
        else
        {
            roomSet.GetComponent<Button>().interactable = false;
            disSolveRoomBtn.GetComponent<Button>().interactable = false;
        }


        if (GameRoomModel.GetInstance().EmpowerTakeIn == true)
            SetText(empowerTakeIn, "开启");
        else
            SetText(empowerTakeIn, "关闭");

        if (GameRoomModel.GetInstance().VieForZhuang == true)
            SetText(zhuang, "开启");
        else
            SetText(zhuang, "换庄");

        if (GameRoomModel.GetInstance().AutoCompute == true)
            SetText(autoNiu, "开启");
        else
            SetText(autoNiu, "关闭");

        switch (GameRoomModel.GetInstance().SameNiu)
        {
            case 0:
                SetText(sameNiu, "比花色");
                break;
            case 1:
                SetText(sameNiu, "平局");
                break;
            case 2:
                SetText(sameNiu, "庄赢");
                break;
        }

        switch (GameRoomModel.GetInstance().OneTimesBet)
        {
            case 0:
                SetText(oneTimesBet, "关闭");
                break;
            case 10:
                SetText(oneTimesBet, "10倍");
                break;
            case 15:
                SetText(oneTimesBet, "15倍");
                break;
            case 20:
                SetText(oneTimesBet, "20倍");
                break;
        }
    }

    private void ShareBtnClick()
    {
        LoginAndShare.Controller.OnClickShareInfo(URLConst.ShareUrl);
        CloseBtnClick();
    }

    private void RoomSetBtnClick()
    {
        UIManager.ChangeUI(UIManager.PageState.GameRoomInfoSet, (GameObject obj) =>
        {
            obj.GetComponent<GameRoomInfoSetPage>().InformationSetting();
        });
    }

    private void DisSolveRoomBtnClick()
    {
        TooL.ShowTipsPage("确认解散本桌游戏？", TooL.TipsPageType.haveCancelPage,
            () =>
            {
                MessageManager.GetInstance().SendMsg1239(2, 0 ,0, 0, GameRoomModel.GetInstance().RoomID);
                CloseBtnClick();
            });
    }
}
